/*
* @Author: Administrator
* @Date:   2019-08-19 07:42:21
* @Last Modified by:   Administrator
* @Last Modified time: 2019-08-19 08:02:25
*/
var http = require('http');

var fs = require('fs');
var path = require('path');

var server = http.createServer(function (req, res) {

	var requestUrl = req.url;
	console.log( requestUrl );

	if( requestUrl.indexOf('html') > -1){

		fs.readFile('./template' + requestUrl, 'utf-8', function (error, dataString) {
			res.end(dataString);
		});

	}else if( requestUrl.indexOf('css') > -1 ){
		// res.setHeader('Content-Type', 'text/css;charset=utf-8');
		fs.readFile('./template' + requestUrl, 'utf-8', function (error, dataString) {
			res.end(dataString);
		});
	}else if( requestUrl.indexOf('js') > -1 ){
		// res.setHeader('Content-Type', 'application/javascript;');

		fs.readFile('./template' + requestUrl, 'utf-8', function (error, dataString) {
			res.end(dataString);
		});
	}else if( requestUrl.indexOf('img') > -1 ){
		fs.readFile('./template' + requestUrl, function (error, dataString) {
			res.end(dataString);
		});


	}else if ( requestUrl.indexOf('lib') > -2 ){
		fs.readFile('./template' + requestUrl, function (error, dataString) {
					res.end(dataString);
				});
						
	}
	
});

server.listen(8080, function () {
	console.log( 'server running...' );
})